<template>
	<view>
		<!-- 头部 -->
		<view style="width: 100%;background-color: #FFFFFF;height: 100%; ">
			<view style="width: 90%;height: 30px;margin: 0 auto;background-color: #FFFFFF;">
				<text style="font-size: 20px;float: left;">日程</text>
				<view style="width: 70px;float: right;">
					<u-icon name="search" color="#9fb3b4" size="30" style="float: right;"></u-icon>
				</view>
			</view>
		</view>
		<!-- 头部结束 -->
		<!-- 日历 -->
		<view>
			<view class="content">
				<ren-calendar ref='ren' :markDays='markDays' :open="false" :disabledAfter='true'
					@onDayClick='onDayClick'></ren-calendar>
				<!-- <view class="change">选中日期：{{curDate}}</view> -->
			</view>
		</view>
		<!-- 日历结束 -->
		<!-- 日程开始 -->
		<view v-for="i in list1">
			<uni-card :title="i.schedulename" style="border-radius: 15px;overflow: hidden;" >
				<view style="width: 420rpx;float: left;"@click="findRC(i.sid)">
					<view style="color: #aabbc2;">
						<u--text type="info" text="日程描述:"></u--text>
					</view>
					<u--text class="uni-body" :lines="2" :text="i.describe" margin="15px"></u--text>
					<u--text class="uni-body" :lines="2" :text="'结束时间：'+formatdate(i.overtime)" size="14px"></u--text>
				</view>
				<view style="float: left; width: 170rpx;margin-left: 10rpx; height: 190rpx;">
					<view style="margin-left: 65rpx;">
						<uni-tag :mark="true" size="default" :text="i.scheduletype ==0 ?'未完成':'已完成'" type="primary" />
						<!-- {{i.scheduletype == 0 ?'未完成':'已完成'}} -->
						<view style="margin-top: 35rpx;margin-left: 25rpx;" @click="xgzt(i.sid)">
							<uni-icons type="checkmarkempty" size="30"></uni-icons>
						</view>
					</view>
				</view>
			</uni-card>
		</view>
		<!--  -->
		<!-- 日程结束 -->
		<!-- 悬浮按钮 -->
		<uni-fab ref="fab" @fabClick="addRicheng()" />
		<!-- 悬浮按钮结束 -->
	</view>
</template>

<script>
	import RenCalendar from '@/components/ren-calendar/ren-calendar.vue'

	export default {
		components: {
			RenCalendar
		},
		data() {
			return {
				curDate: '',
				liste:'',
				markDays: [],
				list: [],
				list1: [],
				// starttime:'',
			}
			// 结束括号
		},
		onReady() {
			let today = this.$refs.ren.getToday().date;
			this.curDate = today;
			this.markDays.push(today);
		},
		onShow(){
			this.findAllRc();
		},
		methods: {
			formatdate(date){
				const dateTime = new Date(date)
				const YY = dateTime.getFullYear()
				const MM =
				    dateTime.getMonth() + 1 < 10 ? '0' + (dateTime.getMonth() + 1) : dateTime.getMonth() + 1
				const DD =
				    dateTime.getDate() < 10 ? '0' + dateTime.getDate() : dateTime.getDate()
				// const hh =
				//     dateTime.getHours() < 10 ? '0' + dateTime.getHours() : dateTime.getHours()
				// const mm =
				//     dateTime.getMinutes() < 10 ? '0' + dateTime.getMinutes() : dateTime.getMinutes()
				// const ss =
				//     dateTime.getSeconds() < 10 ? '0' + dateTime.getSeconds() : dateTime.getSeconds()
				return `${YY}-${MM}-${DD}`
			},
			findAllDateRc() {
				// new Date(this.curDate)
				let date1 = new Date(this.curDate);
				let date =date1.getTime(); 
				// console.log(date,"==============")
				uni.request({
					url: 'http://localhost:9525/fragmentary/findAllDateRc',
					data:{starttime:date},
					method: 'post',
					success: (res) => {
						this.list1 = res.data.data.data
					}
				})
			},
			findRC(sid) {
				uni.navigateTo({
					url: "./findRC?sid=" + sid
				})
			},
			xgzt(sid) {
				console.log("正在修改");
				uni.request({
					url: 'http://localhost:9525/fragmentary/xgzt',
					method: 'POST',
					data: {
						sid: sid,
					},
					dataType: 'json',
					success: (res) => {
						this.list = res.data.data.data
						this.findAllRc();
					}
				})
			},
			// 全查日程
			findAllRc() {
				var that = this
				uni.getStorage({
					key: "user",
					success: function(res) {
						that.liste = res.data
					},
				});
				uni.request({
					url: 'http://localhost:9525/fragmentary/findAllRc?sname='+this.liste.name,
					method: 'POST',
					success: (res) => {
						this.list1 = res.data.data.data
					}
				})
			},
			// 跳转添加日程界面
			addRicheng() {	
				uni.navigateTo({
					url: "./addRiCheng"
				})
			},
			onDayClick(date) {
				// let that =this
				this.curDate = date.date;
				console.log(this.curDate, "/----------------------------------------------")
				this.findAllDateRc();
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f2f2f2;
	}

	.content {

		.change {
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0 auto;
			margin-top: 100rpx;
			height: 100rpx;
			color: #b89249;
			background-color: #21191b;
		}
	}
</style>
